package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.WebUserRole;
import com.wanmait.wanmarecruit.mapper.WebUserRoleMapper;
import com.wanmait.wanmarecruit.service.WebRoleService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.entity.WebRole;
import com.wanmait.wanmarecruit.mapper.WebRoleMapper;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class WebRoleServiceImpl extends ServiceImpl<WebRoleMapper, WebRole> implements WebRoleService {
    @Resource
    private WebUserRoleMapper webUserRoleMapper;
    @Resource
    private WebRoleMapper webRoleMapper;

    @Override
    public List<WebRole> findById(Integer userId) {
        LambdaQueryWrapper<WebUserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WebUserRole::getUserId,userId);
        List<WebUserRole> webUserRoles = webUserRoleMapper.selectList(queryWrapper);
        if (webUserRoles.size()==0)
        {
            return Collections.emptyList();
        }
        List<Integer> roleIds = webUserRoles.stream().map(webUserRole -> webUserRole.getRoleId()).collect(Collectors.toList());
        return webRoleMapper.selectBatchIds(roleIds);
    }
}
